package com.hadoop.mapreduce.fullsort;

import com.hadoop.mapreduce.fullsort.mapper.FullSortMapper;
import com.hadoop.mapreduce.fullsort.partition.FullSortPartitioner;
import com.hadoop.mapreduce.fullsort.reducer.FullSortReducer;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author zouhuixing
 * @date 2023/11/24
 */
public class Application {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Job job = Job.getInstance();
        job.setJarByClass(Application.class);
        job.setPartitionerClass(FullSortPartitioner.class);
        job.setMapperClass(FullSortMapper.class);
        job.setReducerClass(FullSortReducer.class);
        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);
        job.setNumReduceTasks(4);
        //设置任务的输入文件或路径
        FileInputFormat.addInputPath(job, new Path(args[0]));
        //设置任务的输出路径
        FileOutputFormat.setOutputPath(job, new Path(args[1]));

        //启动任务
        job.waitForCompletion(true);
    }
}
